<?php

/*
|--------------------------------------------------------------------------
| Admin Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for admin panel.
| These routes are loaded by the RouteServiceProvider within a group which
| contains the "admin" middleware group.
|
*/

$router->group(['prefix' => 'admin'], function () use ($router) {
    // 获取路由配置
    $routeConfig = config('admin-routes');

    if (empty($routeConfig)) {
        // 如果配置文件不存在，添加默认路由
        $router->get('/', function () {
            return response()->json(['message' => 'Admin API Gateway - No routes configured']);
        });
        return;
    }

    // 直接循环注册路由
    foreach ($routeConfig as $route) {
        $method = strtolower($route['method']);
        $uri = $route['url'];
        $uses = 'Admin\\' . $route['uses'];
        $middleware = $route['middleware'] ?? [];

        // 构建路由配置
        $routeOptions = ['uses' => $uses];
        if (!empty($middleware)) {
            $routeOptions['middleware'] = $middleware;
        }

        // 注册路由
        $router->$method($uri, $routeOptions);
    }
});
